
import { globalUtils } from '../../common/js/global-utils/global-utils-all';
import { uiUtils } from '../../common/js/ui-utils/ui-utils-all';
import Pure from 'pure-frontend';
import uiData from 'ui-data';

/* SOURCE-CODE-START */

"use strict";


Pure.app.viewMain('user-management', function (scope, view) {
  var model = view.getDataModel();
  var jqTable = view.$ui('userTable');
  var jqSearchBtn = view.$ui('searchBtn');

  //
  // 表格
  //

  // 初始表格
  uiUtils.dataGrid.init(jqTable, {
    url: 'api/account/user/pageUsersByCond',
    columns: [
      {
        field: 'id'
      },
      {
        field: 'userName'
      },
      {
        field: 'password',
        formatter: formatPasswordColumn
      },
      {
        field: 'operate',
        'class': 'x-nowrap-items',
        formatter: formatOprationColumn,
        events: {
          'click .assignRole': clickAssignRoleOperationFn
        }
      }
    ]
  });

  function formatPasswordColumn(value, row, index) {
    return '************';
  }

  function formatOprationColumn(value, row, index) {
    return [
      '<a class="assignRole" href="javascript:void(0)">',
      '<span>${t("ui.account.user.operation.assignRole")}</span>',
      '</a>'
    ].join('');
  }

  jqSearchBtn.on(uiUtils.event.CLICK, function () {
    var data = model.getData('searchField.*');
    data = uiData.utils.unprefix(data, 'searchField.');

    uiUtils.dataGrid.newQuery(jqTable, {
      customQuery: data
    });
  });

  // 点击分配角色的事件
  function clickAssignRoleOperationFn(e, value, row, index) {
    scope.showAssignRoleDialog(view, row.id);
  }

});

/* SOURCE-CODE-END */
